﻿<lib:EditControl x:Class="MoPlus.SolutionBuilder.WpfClient.UserControls.Interpreter.SpecTemplateDetailControl"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
			 xmlns:vm="clr-namespace:MoPlus.ViewModel;assembly=MoPlus.ViewModel"
			 xmlns:lib="clr-namespace:MoPlus.SolutionBuilder.WpfClient.Library"
             xmlns:Settings="clr-namespace:MoPlus.SolutionBuilder.WpfClient.Library;assembly=MoPlus.SolutionBuilder.WpfClient"
			 mc:Ignorable="d" 
			 xmlns:avalonEdit="clr-namespace:ICSharpCode.AvalonEdit;assembly=ICSharpCode.AvalonEdit"
			 x:Name="TemplateDetail"
			 d:DesignHeight="300" d:DesignWidth="300">
	<lib:EditControl.CommandBindings>
		<CommandBinding Command="vm:CustomCommands.NextInnerTab" Executed="NextInnerTabExecuted"></CommandBinding>
	</lib:EditControl.CommandBindings>
	<lib:EditControl.Resources>
		<ResourceDictionary>
			<ResourceDictionary.MergedDictionaries>
				<ResourceDictionary Source="../../Resources/Theme.xaml" />
			</ResourceDictionary.MergedDictionaries>
			<BitmapImage x:Key="Icon_DebugGo" UriSource="../../Resources/Images/Debug_Go.png"/>
			<BitmapImage x:Key="Icon_DebugStop" UriSource="../../Resources/Images/Debug_Stop.png"/>
			<Style x:Key="IconImageStyleSmall" TargetType="Image">
				<Setter Property="MaxWidth" Value="16"/>
				<Setter Property="MaxHeight" Value="16"/>
				<Setter Property="Margin" Value="0,0,0,0"/>
			</Style>
			<Style x:Key="TemplateNameInput" BasedOn="{StaticResource LabelInput}" TargetType="{x:Type Label}">
				<Style.Triggers>
					<DataTrigger Binding="{Binding TemplateNameCustomized, Mode=OneWay}" Value="True">
						<DataTrigger.Setters>
							<Setter Property="Foreground" Value="Black" />
						</DataTrigger.Setters>
					</DataTrigger>
					<DataTrigger Binding="{Binding TemplateNameValidationMessage, Converter={StaticResource IsNullOrEmptyConverter}, Mode=OneWay}" Value="False">
						<DataTrigger.Setters>
							<Setter Property="Foreground" Value="Red" />
						</DataTrigger.Setters>
					</DataTrigger>
				</Style.Triggers>
			</Style>
			<Style x:Key="IsTopLevelTemplateInput" BasedOn="{StaticResource BasicCheckBox}" TargetType="{x:Type CheckBox}">
				<Style.Triggers>
					<DataTrigger Binding="{Binding IsTopLevelTemplateCustomized, Mode=OneWay}" Value="True">
						<DataTrigger.Setters>
							<Setter Property="Foreground" Value="Black" />
						</DataTrigger.Setters>
					</DataTrigger>
					<DataTrigger Binding="{Binding IsTopLevelTemplateValidationMessage, Converter={StaticResource IsNullOrEmptyConverter}, Mode=OneWay}" Value="False">
						<DataTrigger.Setters>
							<Setter Property="Foreground" Value="Red" />
						</DataTrigger.Setters>
					</DataTrigger>
				</Style.Triggers>
			</Style>
			<Style x:Key="CategoryNameInput" BasedOn="{StaticResource LabelInput}" TargetType="{x:Type Label}">
				<Style.Triggers>
					<DataTrigger Binding="{Binding CategoryNameCustomized, Mode=OneWay}" Value="True">
						<DataTrigger.Setters>
							<Setter Property="Foreground" Value="Black" />
						</DataTrigger.Setters>
					</DataTrigger>
					<DataTrigger Binding="{Binding CategoryNameValidationMessage, Converter={StaticResource IsNullOrEmptyConverter}, Mode=OneWay}" Value="False">
						<DataTrigger.Setters>
							<Setter Property="Foreground" Value="Red" />
						</DataTrigger.Setters>
					</DataTrigger>
				</Style.Triggers>
			</Style>
			<Style x:Key="NodeNameInput" BasedOn="{StaticResource LabelInput}" TargetType="{x:Type Label}">
				<Style.Triggers>
					<DataTrigger Binding="{Binding NodeNameCustomized, Mode=OneWay}" Value="True">
						<DataTrigger.Setters>
							<Setter Property="Foreground" Value="Black" />
						</DataTrigger.Setters>
					</DataTrigger>
					<DataTrigger Binding="{Binding NodeNameValidationMessage, Converter={StaticResource IsNullOrEmptyConverter}, Mode=OneWay}" Value="False">
						<DataTrigger.Setters>
							<Setter Property="Foreground" Value="Red" />
						</DataTrigger.Setters>
					</DataTrigger>
				</Style.Triggers>
			</Style>
			<Style x:Key="TemplateContentInput" BasedOn="{StaticResource LabelInput}" TargetType="{x:Type Label}">
				<Style.Triggers>
					<DataTrigger Binding="{Binding TemplateContentCustomized, Mode=OneWay}" Value="True">
						<DataTrigger.Setters>
							<Setter Property="Foreground" Value="Black" />
						</DataTrigger.Setters>
					</DataTrigger>
					<DataTrigger Binding="{Binding TemplateContentValidationMessage, Converter={StaticResource IsNullOrEmptyConverter}, Mode=OneWay}" Value="False">
						<DataTrigger.Setters>
							<Setter Property="Foreground" Value="Red" />
						</DataTrigger.Setters>
					</DataTrigger>
				</Style.Triggers>
			</Style>
			<Style x:Key="TemplateOutputInput" BasedOn="{StaticResource LabelInput}" TargetType="{x:Type Label}">
				<Style.Triggers>
					<DataTrigger Binding="{Binding TemplateOutputCustomized, Mode=OneWay}" Value="True">
						<DataTrigger.Setters>
							<Setter Property="Foreground" Value="Black" />
						</DataTrigger.Setters>
					</DataTrigger>
					<DataTrigger Binding="{Binding TemplateOutputValidationMessage, Converter={StaticResource IsNullOrEmptyConverter}, Mode=OneWay}" Value="False">
						<DataTrigger.Setters>
							<Setter Property="Foreground" Value="Red" />
						</DataTrigger.Setters>
					</DataTrigger>
				</Style.Triggers>
			</Style>
			<vm:LabelHelper x:Key="labels" />
		</ResourceDictionary>
	</lib:EditControl.Resources>
	<ScrollViewer VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto" Background="{StaticResource ControlBackgroundBrush}">
		<Grid MinWidth="400" MinHeight="400" DataContextChanged="Grid_DataContextChanged" RenderTransformOrigin="0.5,0.5">
			<Grid.LayoutTransform>
				<TransformGroup>
					<ScaleTransform ScaleX="{Binding Source={x:Static Settings:UserSettingsHelper.Instance}, Path=ControlSize, Mode=TwoWay}"
					                ScaleY="{Binding Source={x:Static Settings:UserSettingsHelper.Instance}, Path=ControlSize, Mode=TwoWay}"/>
				</TransformGroup>
			</Grid.LayoutTransform>
			<Grid.RowDefinitions>
					<RowDefinition Height="Auto"></RowDefinition>
					<RowDefinition Height="*"></RowDefinition>
					<RowDefinition Height="Auto"></RowDefinition>
			</Grid.RowDefinitions>
			<Grid.ColumnDefinitions>
				<ColumnDefinition Width="10"></ColumnDefinition>
				<ColumnDefinition Width="*"></ColumnDefinition>
				<ColumnDefinition Width="10"></ColumnDefinition>
			</Grid.ColumnDefinitions>
			<Label Grid.Row="0" Grid.Column="1" Grid.ColumnSpan="2" Style="{DynamicResource LabelHeader}" Content="{Binding TabTitle, Mode=OneWay}" HorizontalAlignment="Left"/>
			<TabControl Name="tabDesigner" Grid.Row="1" Grid.Column="1" Grid.ColumnSpan="2" TabStripPlacement="Left">
				<TabItem Header="{Binding TemplateOutputHeader}" IsSelected="{Binding IsOutputTabActive, Mode=TwoWay}" Style="{DynamicResource FixedTabItem}">
					<TabItem.InputBindings>
						<KeyBinding Key="F5" Command="{Binding ElementName=TemplateDetail, Path=DataContext.ParseOutputCommand}" />
						<KeyBinding Modifiers="Shift" Key="F5"  Command="{Binding ElementName=TemplateDetail, Path=DataContext.StopOutputCommand}" />
					</TabItem.InputBindings>
					<GroupBox Header="{Binding TemplateOutputHeader}">
						<Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
							<Grid.RowDefinitions>
								<RowDefinition Height="*"></RowDefinition>
								<RowDefinition Height="2"></RowDefinition>
								<RowDefinition Height="Auto"></RowDefinition>
							</Grid.RowDefinitions>
							<Border Name="PlaceHolderBorder2" Margin="7"/>
							<avalonEdit:TextEditor Grid.Row="0" IsReadOnly="{Binding IsDebuggerRunning}" FontSize="{Binding Path=Value, ElementName=outputSlider}" Name="OutputEditor" ToolTip="{Binding TemplateOutputValidationMessage, Mode=OneWay}" ScrollViewer.ScrollChanged="OutputEditor_ScrollChanged" Document="{Binding TemplateOutputDocument, Mode=TwoWay, ValidatesOnDataErrors=True, UpdateSourceTrigger=PropertyChanged}" ShowLineNumbers="True" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto" MinHeight="50"  Height="{Binding ElementName=PlaceHolderBorder2, Path=ActualHeight}" Width="{Binding ElementName=PlaceHolderBorder2, Path=ActualWidth}" Validation.ErrorTemplate="{x:Null}" GotFocus="OutputEditor_GotFocus">
								<avalonEdit:TextEditor.CommandBindings>
									<CommandBinding Command="vm:CustomCommands.PasteTextTags" CanExecute="OutputEditorCanPaste" Executed="PasteOutputTextTags"></CommandBinding>
									<CommandBinding Command="vm:CustomCommands.PasteSplitTextTags" CanExecute="OutputEditorCanPaste" Executed="PasteOutputSplitTextTags"></CommandBinding>
									<CommandBinding Command="vm:CustomCommands.PasteEvaluationTags" CanExecute="OutputEditorCanPaste" Executed="PasteOutputEvaluationTags"></CommandBinding>
									<CommandBinding Command="vm:CustomCommands.PastePropertyTags" CanExecute="OutputEditorCanPaste" Executed="PasteOutputPropertyTags"></CommandBinding>
									<CommandBinding Command="vm:CustomCommands.PasteOutputTags" CanExecute="OutputEditorCanPaste" Executed="PasteOutputOutputTags"></CommandBinding>
								</avalonEdit:TextEditor.CommandBindings>
							</avalonEdit:TextEditor>
							<GridSplitter Grid.Row="1" Height="2" Background="LightSlateGray" Foreground="LightSlateGray" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"></GridSplitter>
							<Grid Grid.Row="2" Width="{Binding ElementName=PlaceHolderBorder2, Path=ActualWidth}">
								<Grid.RowDefinitions>
									<RowDefinition Height="Auto"></RowDefinition>
									<RowDefinition Height="*"></RowDefinition>
								</Grid.RowDefinitions>
								<Grid.ColumnDefinitions>
									<ColumnDefinition Width="Auto"></ColumnDefinition>
									<ColumnDefinition Width="Auto"></ColumnDefinition>
									<ColumnDefinition Width="*"></ColumnDefinition>
								</Grid.ColumnDefinitions>
								<Button Grid.Row="0" Grid.Column="0" Command="{Binding ParseOutputCommand}" ToolTip="{Binding GoButtonToolTip}" Visibility="{Binding OutputDebugGoVisibility}">
									<Image Style="{StaticResource IconImageStyleSmall}" Source="{StaticResource Icon_DebugGo}" />
								</Button>
								<Button Grid.Row="0" Grid.Column="1" Command="{Binding StopOutputCommand}" ToolTip="{Binding StopButtonToolTip}" Visibility="{Binding OutputDebugStopVisibility}">
									<Image Style="{StaticResource IconImageStyleSmall}" Source="{StaticResource Icon_DebugStop}" />
								</Button>
								<Slider x:Name="outputSlider" Grid.Row="0" Grid.Column="2" Minimum="10" Maximum="72" Value="{Binding CodeFontSize, Mode=TwoWay}" VerticalAlignment="Center"/>
								<DataGrid CellEditEnding="EditControl_OutputDebugItemChanged" IsReadOnly="{Binding IsOutputWatchReadOnly}" Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="3" Visibility="{Binding OutputWatchesVisibility}" AutoGenerateColumns="False" CanUserAddRows="True" CanUserDeleteRows="True" HeadersVisibility="Column" SelectionMode="Single" ItemsSource="{Binding OutputDebugItems}">
									<DataGrid.Columns>
										<DataGridTextColumn Header="{Binding Source={StaticResource labels}, Path=DebugExpressionHeader}" Binding="{Binding DebugExpression, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Width="*" />
										<DataGridTextColumn Header="{Binding Source={StaticResource labels}, Path=DebugValueHeader}" Binding="{Binding DebugValue, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Width="3*" IsReadOnly="True">
											<DataGridTextColumn.ElementStyle>
												<Style>
													<Setter Property="TextBlock.TextWrapping" Value="Wrap" />
												</Style>
											</DataGridTextColumn.ElementStyle>
										</DataGridTextColumn>
									</DataGrid.Columns>
								</DataGrid>
							</Grid>
						</Grid>
					</GroupBox>
				</TabItem>
				<TabItem Header="{Binding TemplateContentHeader}" IsSelected="{Binding IsContentTabActive, Mode=TwoWay}" Style="{DynamicResource FixedTabItem}">
					<TabItem.InputBindings>
						<KeyBinding Key="F5" Command="{Binding ElementName=TemplateDetail, Path=DataContext.ParseContentCommand}" />
						<KeyBinding Modifiers="Shift" Key="F5"  Command="{Binding ElementName=TemplateDetail, Path=DataContext.StopContentCommand}" />
					</TabItem.InputBindings>
					<GroupBox Header="{Binding TemplateContentHeader}">
						<Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch" DataContextChanged="Content_DataContextChanged">
							<Grid.RowDefinitions>
								<RowDefinition Height="*"></RowDefinition>
								<RowDefinition Height="2"></RowDefinition>
								<RowDefinition Height="Auto"></RowDefinition>
							</Grid.RowDefinitions>
							<Border Name="PlaceHolderBorder" Margin="7"/>
							<avalonEdit:TextEditor Grid.Row="0" IsReadOnly="{Binding IsDebuggerRunning}" FontSize="{Binding Path=Value, ElementName=contentSlider}" Name="ContentEditor" ToolTip="{Binding TemplateContentValidationMessage, Mode=OneWay}" ScrollViewer.ScrollChanged="ContentEditor_ScrollChanged" Document="{Binding TemplateContentDocument, Mode=TwoWay, ValidatesOnDataErrors=True, UpdateSourceTrigger=PropertyChanged}" ShowLineNumbers="True" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto" MinHeight="50"  Height="{Binding ElementName=PlaceHolderBorder, Path=ActualHeight}" Width="{Binding ElementName=PlaceHolderBorder, Path=ActualWidth}" Validation.ErrorTemplate="{x:Null}" GotFocus="ContentEditor_GotFocus">
								<avalonEdit:TextEditor.CommandBindings>
									<CommandBinding Command="vm:CustomCommands.PasteTextTags" CanExecute="ContentEditorCanPaste" Executed="PasteContentTextTags"></CommandBinding>
									<CommandBinding Command="vm:CustomCommands.PasteSplitTextTags" CanExecute="ContentEditorCanPaste" Executed="PasteContentSplitTextTags"></CommandBinding>
									<CommandBinding Command="vm:CustomCommands.PasteEvaluationTags" CanExecute="ContentEditorCanPaste" Executed="PasteContentEvaluationTags"></CommandBinding>
									<CommandBinding Command="vm:CustomCommands.PastePropertyTags" CanExecute="ContentEditorCanPaste" Executed="PasteContentPropertyTags"></CommandBinding>
								</avalonEdit:TextEditor.CommandBindings>
							</avalonEdit:TextEditor>
							<GridSplitter Grid.Row="1" Height="2" Background="LightSlateGray" Foreground="LightSlateGray" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"></GridSplitter>
							<Grid Grid.Row="2" Width="{Binding ElementName=PlaceHolderBorder, Path=ActualWidth}">
								<Grid.RowDefinitions>
									<RowDefinition Height="Auto"></RowDefinition>
									<RowDefinition Height="*"></RowDefinition>
								</Grid.RowDefinitions>
								<Grid.ColumnDefinitions>
									<ColumnDefinition Width="Auto"></ColumnDefinition>
									<ColumnDefinition Width="Auto"></ColumnDefinition>
									<ColumnDefinition Width="*"></ColumnDefinition>
								</Grid.ColumnDefinitions>
								<Button Grid.Row="0" Grid.Column="0" Command="{Binding ParseContentCommand}" ToolTip="{Binding GoButtonToolTip}" Visibility="{Binding ContentDebugGoVisibility}">
									<Image Style="{StaticResource IconImageStyleSmall}" Source="{StaticResource Icon_DebugGo}" />
								</Button>
								<Button Grid.Row="0" Grid.Column="1" Command="{Binding StopContentCommand}" ToolTip="{Binding StopButtonToolTip}" Visibility="{Binding ContentDebugStopVisibility}">
									<Image Style="{StaticResource IconImageStyleSmall}" Source="{StaticResource Icon_DebugStop}" />
								</Button>
								<Slider x:Name="contentSlider" Grid.Row="0" Grid.Column="2" Minimum="10" Maximum="72" Value="{Binding CodeFontSize, Mode=TwoWay}" VerticalAlignment="Center"/>
								<DataGrid CellEditEnding="EditControl_ContentDebugItemChanged" IsReadOnly="{Binding IsContentWatchReadOnly}" Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="3" Visibility="{Binding ContentWatchesVisibility}" AutoGenerateColumns="False" CanUserAddRows="True" CanUserDeleteRows="True" HeadersVisibility="Column" SelectionMode="Single" ItemsSource="{Binding ContentDebugItems}">
									<DataGrid.Columns>
										<DataGridTextColumn Header="{Binding Source={StaticResource labels}, Path=DebugExpressionHeader}" Binding="{Binding DebugExpression, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Width="*" />
										<DataGridTextColumn Header="{Binding Source={StaticResource labels}, Path=DebugValueHeader}" Binding="{Binding DebugValue, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Width="3*" IsReadOnly="True">
											<DataGridTextColumn.ElementStyle>
												<Style>
													<Setter Property="TextBlock.TextWrapping" Value="Wrap" />
												</Style>
											</DataGridTextColumn.ElementStyle>
										</DataGridTextColumn>
									</DataGrid.Columns>
								</DataGrid>
							</Grid>
						</Grid>
					</GroupBox>
				</TabItem>
				<TabItem Header="{Binding TemplateConfigurationHeader}" IsSelected="{Binding IsConfigTabActive, Mode=TwoWay}" Style="{DynamicResource FixedTabItem}">
					<GroupBox Header="{Binding TemplateConfigurationHeader}">
						<Grid>
							<Grid.RowDefinitions>
								<RowDefinition Height="Auto"></RowDefinition>
								<RowDefinition Height="Auto"></RowDefinition>
								<RowDefinition Height="Auto"></RowDefinition>
								<RowDefinition Height="Auto"></RowDefinition>
							</Grid.RowDefinitions>
							<Grid.ColumnDefinitions>
								<ColumnDefinition Width="Auto"></ColumnDefinition>
								<ColumnDefinition Width="*"></ColumnDefinition>
							</Grid.ColumnDefinitions>
							<Label Grid.Row="0" Grid.Column="0" Style="{DynamicResource TemplateNameInput}" Content="{Binding TemplateNameLabel, Mode=OneWay}" />
							<Label Grid.Row="1" Grid.Column="0" Style="{DynamicResource NodeNameInput}" Content="{Binding NodeNameLabel, Mode=OneWay}" />
							<Label Grid.Row="2" Grid.Column="0" Style="{DynamicResource CategoryNameInput}" Content="{Binding CategoryNameLabel, Mode=OneWay}" />
							<TextBox Grid.Row="0" Grid.Column="1" ToolTip="{Binding TemplateNameValidationMessage, Mode=OneWay}" Text="{Binding TemplateName, Mode=TwoWay, ValidatesOnDataErrors=True, UpdateSourceTrigger=PropertyChanged}" MaxLength="255" Validation.ErrorTemplate="{x:Null}" Loaded="TextBox_Loaded" />
							<ComboBox Grid.Row="1" Grid.Column="1" ToolTip="{Binding NodeNameValidationMessage, Mode=OneWay}" ItemsSource="{Binding Nodes}" SelectedValue="{Binding NodeName, Mode=TwoWay, ValidatesOnDataErrors=True, UpdateSourceTrigger=PropertyChanged}" Validation.ErrorTemplate="{x:Null}" />
							<TextBox Grid.Row="2" Grid.Column="1" ToolTip="{Binding CategoryNameValidationMessage, Mode=OneWay}" Text="{Binding CategoryName, Mode=TwoWay, ValidatesOnDataErrors=True, UpdateSourceTrigger=PropertyChanged}" MaxLength="255" Validation.ErrorTemplate="{x:Null}" />
							<CheckBox Grid.Row="3" Grid.Column="1" Style="{DynamicResource IsTopLevelTemplateInput}" ToolTip="{Binding IsTopLevelTemplateValidationMessage}" Content="{Binding IsTopLevelTemplateLabel, Mode=OneWay}" IsChecked="{Binding IsTopLevelTemplate}" />
						</Grid>
					</GroupBox>
				</TabItem>
			</TabControl>
			<StackPanel Orientation="Horizontal" Grid.Row="2" Grid.Column="1" Margin="5" HorizontalAlignment="Left">
				<Button Command="{Binding UpdateCommand}" Content="{Binding UpdateButtonLabel}"></Button>
				<Button Command="{Binding ResetCommand}" Content="{Binding ResetButtonLabel}"></Button>
				<Button Command="{Binding DefaultsCommand}" Content="{Binding DefaultsButtonLabel}"></Button>
				<Button Command="{Binding CloseConfirmCommand}" Content="{Binding CloseButtonLabel}"></Button>
			</StackPanel>
		</Grid>
	</ScrollViewer>
</lib:EditControl>
